<?php
/**
 * Created by PhpStorm.
 * User: jack Wang
 * Date: 2022/1/5
 * Time: 16:33
 */

require "vendor/autoload.php";

use Pheanstalk\Pheanstalk;

class Beanstalk
{
    private $bea;

    public function __construct()
    {
        $host = PHP_OS == "Linux" ? "127.0.0.1" : "10.0.0.200";
        $this->bea = Pheanstalk::create($host, 11300, 20);
    }

    /**
     * 异步执行sql语句
     * @param string $sql
     * @param array $data
     * @return \Pheanstalk\Job
     */
    public function execSqlAsync(string $sql, array $data)
    {
        $params = [
            'sql' => $sql,
            'data' => $data,
        ];
        $params = json_encode($params);
        return $this->bea->useTube('sqlAsync')->put($params);
    }

}